#pragma once
#include <vector>
#include <string>
#include <ctemplate/template.h>
// #include "oj_model2.hpp"
#include "oj_model.hpp"
namespace ns_view
{
    using namespace ns_model;
    using namespace std;
    const string template_path = "./template_html/";
    class View
    {
    public:
        void AllExpandHtml(const vector<struct Question> &questions, string *out)
        {
            // 题目编号 题目标题 题目难度
            ctemplate::TemplateDictionary root("all_questions");
            // 1、形成路径
            string src_html = template_path + "all_questions.html";
            // 2、加载数据
            for (const auto &q : questions)
            {
                ctemplate::TemplateDictionary *sub = root.AddSectionDictionary("question_list");
                sub->SetValue("number", q.number);
                sub->SetValue("title", q.title);
                sub->SetValue("star", q.star);
            }
            // 3、获取被渲染的网页
            ctemplate::Template *tpl = ctemplate::Template::GetTemplate(src_html, ctemplate::DO_NOT_STRIP);
            // 4、开始渲染
            tpl->Expand(out, &root);
        }
        void OneExpandHtml(const struct Question &q, string *out)
        {
            string src_html = template_path + "one_question.html";
            ctemplate::TemplateDictionary root("one_question");
            root.SetValue("number", q.number);
            root.SetValue("title", q.title);
            root.SetValue("star", q.star);
            root.SetValue("desc", q.desc);
            root.SetValue("header", q.header);
            // 3、获取被渲染的网页
            ctemplate::Template *tpl = ctemplate::Template::GetTemplate(src_html, ctemplate::DO_NOT_STRIP);
            // 4、开始渲染
            tpl->Expand(out, &root);
        }
    };
}